#include "mgrmod.h"

#include <wx/wx.h>
#include <wx/ffile.h>
#include <wx/filesys.h>
#include <wx/fs_arc.h>
#include <wx/fs_mem.h>
#include "common.h"
#include "verinfo.h"
#include "cfgmgr.h"
#include "dictmgr.h"
#include "thememgr.h"
#include "taskmgr.h"
#include "logmgr.h"

class ManagerModule : public wxModule {
    DECLARE_DYNAMIC_CLASS    (ManagerModule);
    
    public:
        ManagerModule() {
            p_logmgr = NULL;
            p_cfgmgr = NULL;
            p_dictmgr = NULL;
            p_thememgr = NULL;
            p_taskmgr = NULL;
        }
        virtual ~ManagerModule() {
            /*delete p_dictmgr;
             delete p_thememgr;
             delete p_taskmgr;
             delete p_cfgmgr;*/
        }
        
        virtual bool OnInit() {
            wxImage::AddHandler(new wxPNGHandler);
            wxFileSystem::AddHandler(new wxArchiveFSHandler);
            wxFileSystem::AddHandler(new wxMemoryFSHandler);
            
            ConfigManager::set_appname(_T(DAODICT_UNIX_NAME));
            
            p_cfgmgr = &ConfigManager::get();
            p_logmgr = &LogManager::get();
            
            delete wxLog::SetActiveTarget(p_logmgr->get_file_target());
            
            // p_cfgmgr = &ConfigManager::get();
            p_dictmgr = &DictManager::get();
            p_thememgr = &ThemeManager::get();
            p_taskmgr = &TaskManager::get();
            
            return true;
        }
        
        virtual void OnExit() {            
            delete p_dictmgr;
            delete p_thememgr;
            delete p_taskmgr;
            delete p_cfgmgr;
            
            delete p_logmgr;
            
            // wxMessageBox(_T("warning"));
        }
        
        void _init_log() {
            // Init wxLog
        }
        
    private:
        ConfigManager* p_cfgmgr;
        DictManager* p_dictmgr;
        ThemeManager* p_thememgr;
        TaskManager* p_taskmgr;
        LogManager* p_logmgr;
        
        wxFFile* _p_logfile;
};

IMPLEMENT_DYNAMIC_CLASS(ManagerModule, wxModule)
